/******************************************************************
 * @Title: BaseController.java 
 * @Package com.omni.web.controllers 
 * @Description: TODO
 * @author Dellinger
 * @date 2015年4月22日 上午12:45:19 
 * @version v1.0 
 * @copyright Omnikennect.com
 ******************************************************************/
package com.omni.web.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/** 
 * @ClassName: BaseController 
 * @Description: TODO 
 * @author Dellinger
 * @date 2015年4月22日 上午12:45:19 
 *  
 */
public class BaseController {
	
	protected final static String SESSION_KEY_AUTH = "ok.secure.auth";
	protected final static String SESSION_KEY_USER = "ok.secure.user";
	
	/**
	 * Gets HttpServletRequest.
	 * 
	 * @Title: getRequest
	 * @return
	 * @return: HttpServletRequest
	 */
	protected static HttpServletRequest getRequest() {

		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return attrs.getRequest();
	}

	/**
	 * Gets HttpSession.
	 * 
	 * @Title: getSession
	 * @return
	 * @return: HttpSession
	 */
	protected static HttpSession getSession() {
		
		return getRequest().getSession();
	}
	
	/**
	 * @Title: Checks logged or not.
	 * @return
	 * @return: boolean
	 */
	protected boolean hasLogged() {
		
		return "1".equals(getSession().getAttribute(SESSION_KEY_AUTH));
	}
}
